﻿@{
    ViewBag.Title = "เลือกรูปแบบรายงาน";
    string strError = ViewBag.Error;
    string strReport = Convert.ToString(ViewBag.Report);

    var bgSources = new KPIS.GERP.WEB.GIMS.MasBudgetSourceService.MasBudgetSourceServiceClient().SelectList(null);
    var bgSourceNoSpecific = bgSources.First();
    var bgSourceSpecific = bgSources.Skip(1);
    // var bgSourceSpecificButNoSource = new SelectListItem() { Text = "ไม่มีแหล่งเงิน", Value = "-1" };
    var bgSourceList = new List<SelectListItem>();
    bgSourceList.Add(bgSourceNoSpecific);
    //bgSourceList.Add(bgSourceSpecificButNoSource);
    bgSourceList.AddRange(bgSourceSpecific);
    bgSourceList[0].Text = "-- ทั้งหมด --";
    string startDate = "01/10/" + (DateTime.Now.Year + 543 + (DateTime.Now.Month >= 10 ? 0 : -1));
}

<style>
    .captionCell {
        text-align: right;
        padding-right: 10px;
    }
    .divFilter {
        padding: 0 0 10px 25px;
        min-height:300px
    }
    .filter1 {
        background-color: #f5f5f5;
        color: #002157;
        font-size: inherit;
        font-weight: inherit;
        font-family: inherit;
        font-style: inherit;
        text-decoration: inherit;
        -webkit-border-radius: 3px;
        -moz-border-radius: 3px;
        border-radius: 3px;
        -moz-box-shadow: 0px 0px 1px 0px #333333;
        -webkit-box-shadow: 0px 0px 1px 0px #333333;
        box-shadow: 0px 0px 1px 0px #333333;
        margin: 10px 0 0 0;
    }
    h3 {
        font-size: 14px;
        font-weight: bold;
        margin-right: 15px;
        margin: 0 0 0 0;
        padding: 0 0 0 0;
    }
    .line1 {
        border: none;
        border-bottom: gray solid 1px;
        margin: 0 14px 20px 0;
        padding: 0 0 0 0;
    }
    .line2 {
        padding-top: 10px;
    }
</style>

<div class="table-header ">
    <table style="width:100%;" >
        <tr>
            <td style="width:150px; text-align: right;">เลือกรูปแบบรายงาน : </td> 
            <td style=" padding-right: 10px; color:black">
                <select id="ddlReportName" name="ReportName" class="chzn-select input-xlarge" data-manualwidth="100%">
                    <option value="Report1">1. รายงานทะเบียนคุมทรัพย์สิน</option>
                    <option value="Report2">2. รายงานวัสดุคงเหลือ</option>
                    <option value="Report4">3. รายงานสินค้าและวัตถุดิบ</option>
                    <option value="Report5">4. รายงานค่าเสื่อม</option>
                </select>
            </td>
        </tr>
    </table>
</div> 
 
            @if (!string.IsNullOrWhiteSpace(strError))
            {
                <h3><label id="lblError" class="red">@strError</label></h3>
            }


<div id="divReport1" class="divFilter filter1">

    <h3>
        1. รายงานทะเบียนคุมทรัพย์สิน
    </h3>
    <hr class="line1" />

    <table border="0" style="width: 100%;  " > 
        <tr style="height:40px;">
            <td class="captionCell" style="width:219px" valign="middle"> กรุณาเลือกรูปแบบครุภัณฑ์ </td>
            <td>
                @Html.DropDownList("DdlShowIsLowerAsset", new[]
                {
                    new SelectListItem { Text = "ครุภัณฑ์ปกติ", Value = "false", Selected = true},
                    new SelectListItem { Text = "ครุภัณฑ์ต่ำกว่าเกณฑ์", Value = "true"}
                }
                    , new
                    {
                        id = "DdlShowIsLowerAsset",
                        @class = "chzn-select",
                        data_placeholder = "เลือก...",
                        style = "display: none;"
                    })
            </td>
        </tr>
        <tr style ="height:80px"></tr>
        <tr style="height:10px">
            <td colspan="2">
                <hr class="line1" />
            </td>
        </tr>
        <tr style="height:50px">
            <td colspan="2">
                <center>
                    <a onclick='javascript: report1(); ' role="button" class="btn btn-large btn-success">ออกรายงาน</a>
                </center>
            </td>
        </tr>
    </table> 
</div>

            <div id="divReport2" style="display: none;" class="divFilter filter1">
                <h3>
                    2. รายงานวัสดุคงเหลือ
                </h3>
                <hr class="line1" />

                <table>
                    <tr>
                        <td class="captionCell" style="width:200px">ค้นรหัสสินค้า </td>
                        <td>@Html.TextBox("CusNoStart2", "", new { placeholder = "ค้นจากเลขรหัสไม่ต้องใช้รหัสเต็ม" })</td>
                        <td class="captionCell" style="width:200px">ถึงรหัสสินค้า</td>
                        <td>@Html.TextBox("CusNoEnd2", "", new { placeholder = "ถ้าค้นเป็นช่วงต้องใช้รหัสเต็ม" }) </td>
                    </tr>
                    <tr>
                        <td class="captionCell">วันที่ต้องการออกรายงานวัสดุคงเหลือ </td>
                        <td>
                            @Html.TextBox("RecDate2", null, new
                            {
                                id = "RecDate2",
                                @class = "date-picker",
                                @data_provide = "datepicker",
                                @data_date_language = "th-th",
                                @placeholder = ViewData["placeholder"]
                            })
                        </td>
                        <td class="captionCell"> เลือกแสดงเฉพาะ </td>
                        <td>
                            @Html.DropDownList("DdlShowUnTransaction", new[]
                            {
                                new SelectListItem { Text = "แสดงที่มียอดเท่านั้น", Value = "NotZero", Selected = true},
                                new SelectListItem { Text = "แสดงที่ไม่มียอดด้วย", Value = "AllowZero"}
                            }
                                , new
                                {
                                    id = "DdlShowUnTransaction",
                                    @class = "chzn-select",
                                    data_placeholder = "แสดงเฉพาะที่วัสดุมียอด...",
                                    style = "display: none;"
                                })
                        </td>
                    </tr>
                    <tr>
                        <td class="captionCell">แหล่งเงิน</td>
                        <td>
                            @Html.DropDownList("BgSourceId", bgSourceList
                                , new { id = "ddlBgSourceId", @class = "chzn-select", data_placeholder = "เลือกแหล่งเงิน...", style = "display: none;" })
                        </td>
                        <td class="captionCell">หมวดพัสดุ</td>
                        <td>
                            @Html.DropDownList("ResGrpId", new KPIS.GERP.WEB.GIMS.MasResourceService.MasResourceServiceClient()
                                .SelectListResourceGroup(new KPIS.GERP.Models.ICM.MasResourceGroup() { ResTypeId = 1 })
                                , new { id = "ddlResGrpId", @class = "chzn-select", data_placeholder = "เลือกหมวดวัสดุ...", style = "display: none;" })
                        </td>
                    </tr>
                </table>
                <hr class="line1 line2" />
                <center>
                    <a onclick="report2()" role="button" class="btn btn-large btn-success">ออกรายงาน</a>@*href='@Url.Action("Report2")'*@
                </center>
            </div>

            <div id="divReport3" style="display: none;" class="divFilter filter1">
                <h3>
                    3. รายงานสำรวจครุภัณฑ์ต่ำกว่าเกณฑ์ <!--(รวมไปกับข้อ 1 แล้ว)-->
                </h3>
                <hr class="line1" />
                <center>
                    <a href='@Url.Action("Report3")' role="button" class="btn btn-large btn-success">ออกรายงาน</a>
                </center>
            </div>

            <div id="divReport4" style="display: none;" class="divFilter filter1">
                <h3>
                    3. รายงานสินค้าและวัตถุดิบ
                </h3>
                <hr class="line1" />
                
                <table width="100%">
                    <tr>
                        <td class="captionCell" width="200px;">ค้นรหัสสินค้า</td>
                        <td>@Html.TextBox("CusNoStart", "", new { placeholder = "ค้นจากเลขรหัสไม่ต้องใช้รหัสเต็ม" })</td>
                        <td class="captionCell" width="200px;">ถึง</td>
                        <td>@Html.TextBox("CusNoEnd", "", new { placeholder = "ค้นจากเลขรหัสไม่ต้องใช้รหัสเต็ม" })</td>
                    </tr>
                    <tr>
                        <td class="captionCell">ตั้งแต่วันที่</td>
                        <td>@Html.TextBox("StartDate", null, new { id = "StartDate4", @class = "date-picker", value=startDate,
                           @data_provide = "datepicker", @data_date_language = "th-th", @placeholder = ViewData["placeholder"] })
</td>
                        <td class="captionCell">ถึง</td>
                        <td>@Html.TextBox("EndDate", null, new { id = "EndDate4", @class = "date-picker", 
                           @data_provide = "datepicker", @data_date_language = "th-th", @placeholder = ViewData["placeholder"] })</td>
                    </tr>
                    <tr>
                        <td class="captionCell">แหล่งเงิน</td>
                        <td>@Html.DropDownList("BgSourceIdReport4", bgSourceList
                                , new { id = "BgSourceIdReport4", @class = "chzn-select", data_placeholder = "เลือกแหล่งเงิน...", 
                                    style = "display: none;" })</td>
                        <td class="captionCell"></td>
                        <td></td>
                    </tr>
                </table> 
                <hr class="line1 line2" />
                <center>
                    <a onclick="report4()" role="button" class="btn btn-large btn-success ">ออกรายงาน</a>
                </center>
            </div>
 

<div id="divReport5" style="display: none;" class="divFilter filter1">
    <h3>
        4. รายงานค่าเสื่อมราคา
    </h3>
    <hr class="line1" />
    <table width="100%"> 
        <tr>
            <td class="captionCell">คำนวนการหักค่าเสื่อมตั้งแต่วันที่</td>
            <td>
                @Html.TextBox("DepricateDateStart", null, new
                {
                    id = "DepricateDateStart",
                    @class = "date-picker",
                    @data_provide = "datepicker",
                    @data_date_language = "th-th",
                    value = startDate,
                    @placeholder = "วันที่คิดค่าเสื่อม"
                })
            </td> 
            <td class="captionCell">จนถึงวันที่</td>
            <td>
                @Html.TextBox("DepricateDateEnd", null, new
                {
                    id = "DepricateDateEnd",
                    @class = "date-picker",
                    @data_provide = "datepicker",
                    @data_date_language = "th-th",
                    @placeholder = "ถึงวันที่"
                })
            </td> 
        </tr> 
    </table>
    <hr class="line1 line2" />
    <center>
        <a onclick='report5()' role="button" class="btn btn-large btn-success">ออกรายงาน</a>
    </center>
</div>

    @section scripts
{
        <script type="text/javascript">

    function report1() {
        window.location = '@Url.Action("Report1")' + '?DdlShowIsLowerAsset=' + $("#DdlShowIsLowerAsset").val();
    }

    function report2() {
        var ResGrpId = $("#ddlResGrpId").val();
        var BgSourceId = $("#ddlBgSourceId").val();

        window.location = '@Url.Action("Report2")' + '?ResGrpId=' + ResGrpId +
            '&BgSourceId=' + BgSourceId +
            '&RecDate2=' + $("#RecDate2").val() +
            '&CusNoStart2=' + $("#CusNoStart2").val() +
            '&CusNoEnd2=' + $("#CusNoEnd2").val() +
            '&DdlShowUnTransaction=' + $("#DdlShowUnTransaction").val();
    }

    function report4() {
        //var StartDate = $("#StartDate4").val();
        //var EndDate = $("#EndDate4").val();
        //alert(EndDate);

        window.location = '@Url.Action("Report4")' + '?RecStartDate=' + $("#StartDate4").val() +
            '&RecEndDate=' + $("#EndDate4").val() +
            '&BgSourceIdReport4=' + $('#BgSourceIdReport4').val() +
            '&CusNoStart=' + $("#CusNoStart").val() +
            '&CusNoEnd=' + $("#CusNoEnd").val();
    }
    function report5() {
        //var StartDate = $("#StartDate4").val();
        //var EndDate = $("#EndDate4").val();
        //alert(EndDate);

        var url1 = '@Url.Action("Report5")' + '?DepricateDateStart=' + $("#DepricateDateStart").val() +
            '&DepricateDateEnd=' + $("#DepricateDateEnd").val();
        //alert(url1);
        window.location = url1;
    }

    $(document).ready(function () {
        @*$('#ddlReportName').val(@strReport).trigger("liszt:updated");*@

        $('#ddlReportName').change(function () {
            var reportName = $('#ddlReportName').val();
            var divReport1 = $('#divReport1');
            var divReport2 = $('#divReport2');
            var divReport3 = $('#divReport3');
            var divReport4 = $('#divReport4');
            var divReport5 = $('#divReport5');

            if (reportName == null) {

            }
            else if (reportName == "Report1" || reportName == "Report3") {
                divReport1.show();
                divReport2.hide();
                divReport3.hide();
                divReport4.hide();
                divReport5.hide();
            }
            else if (reportName == "Report2") {
                divReport1.hide();
                divReport2.show();
                divReport3.hide();
                divReport4.hide();
                divReport5.hide();
            }
            else if (reportName == "Report3") {
                divReport1.hide();
                divReport2.hide();
                divReport3.show();
                divReport4.hide();
                divReport5.hide();
            }
            else if (reportName == "Report4") {
                divReport1.hide();
                divReport2.hide();
                divReport3.hide();
                divReport4.show();
                divReport5.hide();
            }
            else if (reportName == "Report5") {
                divReport1.hide();
                divReport2.hide();
                divReport3.hide();
                divReport4.hide();
                divReport5.show();
            }
        });

        $('#ddlReportName').change();
        $('#DepricateDateStart').val('@startDate');
        $('#StartDate4').val('@startDate');
    });

        </script>
    }